<?php
if (get_magic_quotes_gpc() === 1) exit;

session_start();
if (empty($_GET['p'])) $_GET['p'] = 'index';
if ( ( ( strpos($_GET['p'], 'adminisztracio') === 0 &&
         $_GET['p'] !== 'adminisztracio' ) ||
       $_GET['p'] === 'phpinfo' ) &&
     empty($_SESSION['id']) )
{
	$queryString = '';
	foreach ($_GET as $key => $value)
	{
		if ($key !== 'p')
			$queryString .= '&'.$key.'='.$value;
	}
	if (strlen($queryString) !== 0) 
		$queryString = substr_replace($queryString, '?', 0, 1);
   header('Location: '.$prefix.'/adminisztracio?returnUrl='.urlencode($_GET['p'].$queryString));
   exit;
}

$pageCreatedFromCookies = false;
if (count($_POST) !== 0)
{
	setcookie($_GET['p'], serialize($_POST));
} else {
	if (isset($_GET['vissza']) && isset($_COOKIE[$_GET['p']]))
	{
		$_POST = unserialize($_COOKIE[$_GET['p']]);
		$pageCreatedFromCookies = true;
	}
}

$isFirst = null;

if ($_SERVER['SERVER_NAME'] === 'localhost')
{
   $folder = 'd:/xampp/private_html';
   $folder_public = 'd:/xampp/htdocs';
} else {
   $folder = '/home/kincsker/private_html';
   $folder_public = '/home/kincsker/public_html';
}

if (!($_GET['p'] === 'kep-kicsi' ||
      $_GET['p'] === 'kep-kozepes' ||
      $_GET['p'] === 'kep-mini' ||
      $_GET['p'] === 'kep-eredeti'))
{
   // VARYING CONFIGURATION SETTINGS
   $db_hostname = 'localhost';
   if ($_SERVER['SERVER_NAME'] === 'localhost')
   {
      $db_username = 'root';
      $db_password = '';
   } else {
      $db_username = 'kincsker';
      $db_password = '';
   }
   $db_dbname = 'kincsker_Kincskereso';

   if (substr($_SERVER['REQUEST_URI'],0,10) === '/~kincsker') $prefix = '/~kincsker';
   else $prefix = '';

   require_once($folder.'/functions/queryBase.function');
   require_once($folder.'/functions/query.function');
   require_once($folder.'/functions/queryOneRow.function');
   require_once($folder.'/functions/queryScalar.function');
   require_once($folder.'/functions/queryInsertID.function');
   require_once($folder.'/functions/_mysql_real_escape_string.function');
   require_once($folder.'/functions/__.function');
   require_once($folder.'/functions/___.function');
   require_once($folder.'/functions/GetMonthName.function');
   require_once($folder.'/functions/setColors.function');
   require_once($folder.'/functions/my_print_r.function');
   require_once($folder.'/functions/create_thumbnail.function');
   require_once($folder.'/functions/query.function');
   require_once($folder.'/functions/IsCurrentRequestUnder.function');
   require_once($folder.'/functions/TreeViewHelper.function');
   require_once($folder.'/functions/OpenTreeViewNode.function');
   require_once($folder.'/functions/DrawSampleRectangle.function');
   require_once($folder.'/functions/DrawTreeViewImages.function');
   require_once($folder.'/functions/LinkForPictureInGallery.function');
   require_once($folder.'/functions/PopulateSiteMapPath.function');
   require_once($folder.'/functions/MoveMenuItem.function');
   require_once($folder.'/functions/ReplaceNullOrEmpty.function');
   require_once($folder.'/functions/IsPostBack.function');

   require_once($folder.'/plugins/box_simple_footer.plugin');
   require_once($folder.'/plugins/box_simple_header.plugin');
   require_once($folder.'/plugins/box_footer.plugin');
   require_once($folder.'/plugins/box_header.plugin');
   require_once($folder.'/plugins/box_middle.plugin');
   require_once($folder.'/plugins/dataList.plugin');
   require_once($folder.'/plugins/table.plugin');
   require_once($folder.'/plugins/extendedTable.plugin');
   require_once($folder.'/plugins/menu.plugin');
   require_once($folder.'/plugins/repeater.plugin');
   require_once($folder.'/plugins/paginator.plugin');
   require_once($folder.'/plugins/htmlSelect.plugin');
   require_once($folder.'/plugins/inputHidden.plugin');
   require_once($folder.'/plugins/inputText.plugin');
   require_once($folder.'/plugins/label.plugin');
   require_once($folder.'/plugins/inputTextArea.plugin');
   require_once($folder.'/plugins/treeView.plugin');
   require_once($folder.'/plugins/_treeView.plugin');
   require_once($folder.'/plugins/siteMapPath.plugin');

	$data = query(
			'SELECT `p`.`value`
			FROM `parameter` `p` 
			WHERE `p`.`key` IN ( \'background_images_last_update_id\', 
				\'client_resources_id\' )
			ORDER BY `p`.`key`',
			null);
   
	$backgroundImagesLastUpdateId = (string)($data[0]['value']);
	$clientResourcesId = (string)($data[1]['value']);
   
   $postKeys = array_keys($_POST);
   foreach ($postKeys as &$postKey)
   {
      if (preg_match('/^submitaction_.*/', $postKey) === 1)
      {   
         $_POST['formaction'] = substr($postKey, 13);
         break;
      }
   }
   if (!empty($_POST['formaction']) && !$pageCreatedFromCookies)
   {
      include($folder.'/actions/'.$_POST['formaction'].'.action');
   }

   define('HTTP_SERVER', 'http://www.kincskeresomuhely.hu');
   define('HTTPS_SERVER', 'https://87.229.73.63/~kincsker');
   /* if(strpos($_SERVER['REQUEST_URI'],'/adminisztracio')!==0 &&
      strpos($_SERVER['REQUEST_URI'],'/admin')!==0 &&
      strpos($_SERVER['REQUEST_URI'],'/kep-kozepes')!==0 &&
      strpos($_SERVER['REQUEST_URI'],'/kep-mini')!==0 &&
      strpos($_SERVER['REQUEST_URI'],'/kep-eredeti')!==0 &&
      strpos($_SERVER['REQUEST_URI'],'/kep-kicsi')!==0 &&
      strpos($_SERVER['REQUEST_URI'],'/css/jquery/ui-lightness/images')!==0)
   {
      $host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
      if (!ereg('crawl-.*\\.googlebot\\.com', $host) &&
         !ereg('crawl-.*\\.cuil\\.com', $host) &&
         !ereg('host-50-022\\.comunique\\.hu', $host) &&
         !ereg('crawl6\\.dotnetdotcom\\.org', $host) &&
         !ereg('spider12\\.yandex\\.ru', $host) &&
         !ereg('.*\\.crawl\\.yahoo\\.net', $host) &&
         !ereg('msnbot-.*\\.search\\.msn\\.com', $host))
      {
         query(
            'INSERT INTO log (address,host,created,request,referer) VALUES (?,?,now(),?,?)', 
            array(
               $_SERVER['REMOTE_ADDR'], 
               gethostbyaddr($_SERVER['REMOTE_ADDR']), 
               $_SERVER['REQUEST_URI'], 
               $_SERVER['HTTP_REFERER']));
      }
   } */
}

if (!file_exists($folder.'/pages/'.$_GET['p'].'.php')) die();
require($folder.'/pages/'.$_GET['p'].'.php');
require($folder.'/pages/'.$_GET['p'].'.tpl');

?>
